<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>分类标识管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/extends/zTree_v3/css/zTreeStyle/zTreeStyle.css"/>
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>

<div class="sysTypeKeyTable" style="margin: 10px">
    <table id="sysTypeKeyTable" lay-filter="sysTypeKeyTable"></table>
</div>
<!-- 列表头部工具栏 -->
<script type="text/html" id="sysTypeKeyHeaderToolsBar">
    <div class="ccpui-enterSel">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm" lay-event="add">
                <i class="layui-icon layui-icon-add-1"></i>
                <span>新增</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="query">
                <i class="layui-icon layui-icon-search"></i>
                <span>查询</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="clears">
                <i class="layui-icon layui-icon-refresh"></i>
                <span>重置</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-submit lay-filter="btnSubmit">
                <i class="layui-icon layui-icon-app"></i>
                <span>保存排序</span>
            </a>
        </div>
        <form class="layui-form" action="" lay-filter="sysTypeKeyQueryForm" style="margin-right: 30px;">
            <div class="layui-row" style="margin-top: 10px;">
                <div class="selch table-top-filter">
                    <div class="table-filter-alone">
                        <label class="layui-form-label">分类名称</label>
                        <input type="text" class="layui-input filter-value" id="typeName" name="Q_typeName_SL" placeholder="分类名称"/>
                    </div>
                    <div class="table-filter-alone">
                        <label class="layui-form-label">分类键值</label>
                        <input type="text" class="layui-input filter-value" id="typeKey" name="Q_typeKey_SL" placeholder="分类键值"/>
                    </div>
                </div>
            </div>
        </form>
    </div>

</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="sysTypeKeyRightToolsBar">
    <a class="layui-btn layui-btn-xs" lay-event="moveUp">上移</a>
    <a class="layui-btn layui-btn-xs" lay-event="moveDown">下移</a>
    {{# if(d.flag == '0' ){ }}
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{# } }}
</script>
<script src="${ctx}/extends/jquery.min.js" type="text/javascript"></script>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script src="${ctx}/extends/zTree_v3/js/jquery.ztree.all.min.js" type="text/javascript"></script>
<script src="${ctx}/extends/zTree_v3/js/jquery.ztree.exhide.min.js" type="text/javascript"></script>
<script>
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'setter', 'form', 'common','totalFilter','commons','jquery','layer'], function () {
        var table = layui.table;
        var setter = layui.setter;
        var form = layui.form;
        var common = layui.common;
        var commons = layui.commons;
        var layer = layui.layer;
        var $ = layui.jquery;
        var totalFilter = layui.totalFilter;
        common.tableSort('sysTypeKeyTable');

        var tableH=commons.tabHeight('full-70');

        //第一个实例
        table.render({
            elem: '#sysTypeKeyTable'
            ,height:tableH
            ,url: serverPath.basePath + '/system/sysTypeKey/list'
            ,defaultToolbar: ['filter', 'print']
            ,toolbar: '#sysTypeKeyHeaderToolsBar'
            ,method: 'post'
            ,cols: [[ //表头
                {field: 'sn', type: 'numbers', title: '序号'}
                ,{type: 'checkbox'}
                ,{field: 'typeId', title: '分类Id',hide:true,sort:true, sortname: 'typeid'}
                ,{field: 'typeName', title: '分类名称',sort:true, sortname: 'typename'}
                ,{field: 'typeKey', title: '分类Key',sort:true, sortname: 'typekey'}
                ,{field: 'flag', title: '系统',sort:true, sortname: 'flag',templet:function (d) {
                    if(d.flag == "1"){
                        return "系统默认";
                    }else{
                        return "自定义";
                    }
                }}
                ,{field: 'type', title: '类型',sort:true, sortname: 'type',templet:function (d) {
                    if(d.type == '0'){
                        return "平铺结构";
                    }else{
                        return "树形结构";
                    }
                }}
                ,{
                    align: 'center',
                    title: '管理',
                    toolbar: '#sysTypeKeyRightToolsBar'
                }
            ]],done:function () {
                common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel');
            }
        });

        totalFilter.init('sysTypeKeyTable');
        commons.reflashDate({startName:'.start_time',endName:'.end_time'});

        function reflashQuery(isClear) {
            common.tableConditionRender("sysTypeKeyTable","sysTypeKeyQueryForm",{where:{}},isClear,"true");
        }

        table.on('toolbar(sysTypeKeyTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            var _this = this;
             var typeName = $("#typeName").val();
             var typeKey = $("#typeKey").val();
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2,
                        title: ['新增数据'],
                        area: ['500px', '300px'],
                        content: serverPath.basePath + "/system/sysTypeKey/view/add"
                    });
                    break;
                case "query":
                    reflashQuery(false);
                    totalFilter.init('sysTypeKeyTable');
                    break;
                case "clears":
                    reflashQuery(true);
                    totalFilter.init('sysTypeKeyTable');
                    break;
            };
        });

        form.on("submit(btnSubmit)",function () {
//            var displayFieldData = [];
            var displayFieldData = "";
            $(".sysTypeKeyTable .layui-table-body tr").each(function (i,item) {
                var tdInfo = $(item).children();
                var typeId;
                if($(tdInfo[2]).text()){
                    typeId = $(tdInfo[2]).text();
                }
//                displayFieldData.push(typeId);
                displayFieldData = displayFieldData + typeId + ",";
            });
            $.ajax({
                url:serverPath.workflowPath + setter.sysLinkPath + "sysTypeKey/saveSort",
                type: "post",
                data: {ids:displayFieldData},
                dataType: 'json',
                contextType:'json',
                success: function (data) {
                    layer.alert(data.msg);
                    //执行重载
//                    reflashQuery(true);
//                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                    table.reload('sysTypeKeyTable');
                    totalFilter.init('sysTypeKeyTable');
                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert(data.msg);
                    //执行重载
//                    reflashQuery(true);
//                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                    table.reload('sysTypeKeyTable');
                    totalFilter.init('sysTypeKeyTable');
                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                }
            })
        })

        table.on('tool(sysTypeKeyTable)', function(obj) {
            var data = obj.data, //获得当前行数据
                    layEvent = obj.event; //获得 lay-event 对应的值
            var data_tr = $(this);
            switch(layEvent){
                case "edit":
                    layer.open({
                        type: 2,
                        area: ['500px', '300px'],
                        title: ['修改数据'],
                        content: serverPath.basePath + '/system/sysTypeKey/view/add?typeId='+data.typeId
                    });
                    break;
                case "del":
                    delFun(data,data.typeId);
                    break;
                case 'moveUp':
                    var tr = $(data_tr).parent().parent().parent();
                    $(tr).insertBefore($(tr).prev());
                    break;
                case 'moveDown':
                    var tr = $(data_tr).parent().parent().parent();
                    $(tr).insertAfter($(tr).next());
                    break;
            }
        });

        function delFun(data,id) {
            if (data.length === 0) {
                layer.msg('请先选择一行数据!');
            } else {
                layer.confirm('确定删除当前数据吗?', function (index) {
                    layer.close(index);
                    $.ajax({
                        url: serverPath.basePath + "/system/sysTypeKey/del",
                        type: "post",
                        data: {id:id},
                        dataType: 'json',
                        success: function (data) {
                            layer.alert(data.msg);
                            //执行重载
//                            reflashQuery(true);
//                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                            table.reload('sysTypeKeyTable');
                            totalFilter.init('sysTypeKeyTable');
                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert(data.msg);
                            //执行重载
//                            reflashQuery(true);
//                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                            table.reload('sysTypeKeyTable');
                            totalFilter.init('sysTypeKeyTable');
                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                        }
                    })
                })
            }
        }

        window.Initialization = function () {
            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
        };
        /*刷新时间控件*/
        commons.reflashDate({startName:'.start_time',endName:'.end_time'});
        common.tableSort("sysTypeKeyTable",{show:window.Initialization});
    });
</script>
</body>
</html>
<link rel="stylesheet" href="${ctx}/css/font/iconfontie.css" media="all"/>
<link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>